﻿using FirstFloor.ModernUI.Windows.Controls;
using SelElectCalcModernUI.ViewModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SelElectCalcModernUI
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : ModernWindow
    {
        public MainWindow()
        {
            InitializeComponent();
            ViewModelLocator.MessageShow += (s) => MessageBox.Show(s);
            ViewModelLocator.JumpPage += (s) =>this.ContentSource = new Uri(s, UriKind.Relative);
            ViewModelLocator.SaveFile += ViewModelLocator_SaveFile;
            ViewModelLocator.DialogShow += ViewModelLocator_DialogShow;
            Closing += (s, e) => ViewModelLocator.Cleanup();
        }

        private bool ViewModelLocator_DialogShow(string path)
        {
            return new ShowDialogWindow().ShowDialog(path);
        }

        private Stream ViewModelLocator_SaveFile(string ext)
        {
            Microsoft.Win32.SaveFileDialog sd = new Microsoft.Win32.SaveFileDialog();
            sd.DefaultExt = ext;
            sd.Filter = "csv文件|*.csv";
            if (sd.ShowDialog() == true)
                return sd.OpenFile();
            else
                return null;
        }
    }
}
